package com.hongxun.design.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hongxun.design.R;
import com.hongxun.design.bean.SectionListBean;

import java.util.List;

/**
 * Created by zerdoor_pc on 2016/6/6.
 */
public class SectionAdapter extends BaseAdapter {
    Context context;
    List<SectionListBean> listBeans;
    LayoutInflater inflater;

    public SectionAdapter(Context context, List<SectionListBean> listBeans) {
        this.context = context;
        this.listBeans = listBeans;
        inflater = LayoutInflater.from(context);
    }

    public void setRefresh(List<SectionListBean> listBeans){
        this.listBeans=listBeans;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return listBeans.size();
    }

    @Override
    public Object getItem(int i) {
        return listBeans.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holldler holldler = null;
        if (view == null) {
            view = inflater.inflate(R.layout.listview_item_section, null);
            holldler = new Holldler(view);
            view.setTag(holldler);
        } else {
            holldler = (Holldler) view.getTag();
        }

        SectionListBean bean= (SectionListBean) getItem(i);
        try {

            holldler.corss.setText(bean.getCorss());
            holldler.section.setText(bean.getSection());

        } catch (Exception e) {
        }

        return view;
    }

    class Holldler {
        TextView section, corss;
        Holldler(View v) {
            section = (TextView) v.findViewById(R.id.section);
            corss = (TextView) v.findViewById(R.id.corss);
        }
    }

}
